package com.yanqu.road.server.manager.strongholdwar;

import com.yanqu.road.dao.impl.activity.stronghold.CrossStrongholdItemDonateDaoImpl;
import com.yanqu.road.dao.impl.activity.stronghold.CrossStrongholdSilverDonateDaoImpl;
import com.yanqu.road.dao.impl.activity.stronghold.CrossStrongholdUnionBaseDaoImpl;
import com.yanqu.road.entity.activity.stronghold.*;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.rank.stronghold.CrossActivityUnionRank;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.logic.bussiness.player.activity.UserStrongholdBusiness;
import com.yanqu.road.logic.cross.stronghold.CrossActivityUnionRankModel;
import com.yanqu.road.pb.rank.UnionActivityRankProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;


public class StrongholdWarMgr extends TempMgr {

    private static Map<Integer, Map<String, StrongholdUnionBase>> activityUnionBaseMap;

    /**
     * 银两捐献
     */
    private static Map<Integer, Map<String, Map<Long, StrongholdSilverDonate>>> silverDonateMap;
    /**
     * 道具捐献
     */
    private static Map<Integer, Map<String, Map<Long, Map<Integer, StrongholdItemDonate>>>> itemDonateMap;

    /**
     * 派遣的防守门客信息，每一次结束派遣后，同步到跨服
     */
    private static Map<Integer, Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>>> defendPatronsMap;


    private static Map<Integer, Map<Long, StrongholdTradeData>> tradeMap;


    /**
     * 获取联盟所有防守门客
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    @Deprecated
    private static Map<Long, List<StrongholdEliminateDefendPatrons>> getUnionDefendPatronsMap(int activityId, String unionUid) {
        synchronized (defendPatronsMap) {
            Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>> unionMap = defendPatronsMap.get(activityId);
            if (unionMap == null) {
                unionMap = new ConcurrentHashMap<>();
                defendPatronsMap.put(activityId, unionMap);
            }
            Map<Long, List<StrongholdEliminateDefendPatrons>> patronsMap = unionMap.get(unionUid);
            if (patronsMap == null) {
                patronsMap = new ConcurrentHashMap<>();
                unionMap.put(unionUid, patronsMap);
            }
            return patronsMap;
        }
    }

    /**
     * 获取联盟据点（捐献数据）
     *
     * @param activityId
     * @param unionId
     * @return
     */
    private static StrongholdUnionBase getUnionBase(int activityId, String unionId) {
        synchronized (activityUnionBaseMap) {
            Map<String, StrongholdUnionBase> unionBaseMap = activityUnionBaseMap.get(activityId);
            if (unionBaseMap == null) {
                unionBaseMap = new ConcurrentHashMap<>(4);
                activityUnionBaseMap.put(activityId, unionBaseMap);
            }
            StrongholdUnionBase unionBase = unionBaseMap.get(unionId);
            if (unionBase == null) {
                unionBase = initNewUnionBase(activityId, unionId);
                unionBaseMap.put(unionId, unionBase);
            }
            return unionBase;
        }
    }

    /**
     * 初始化联盟数据
     *
     * @param activityId
     * @param unionId
     * @return
     */
    private static StrongholdUnionBase initNewUnionBase(int activityId, String unionId) {
        StrongholdUnionBase unionBase;
        unionBase = new StrongholdUnionBase();
        unionBase.setActivityId(activityId);
        unionBase.setUnionUid(unionId);
        unionBase.setLv(0);
        List<Integer> processList = new ArrayList<>();
        processList.add(0);
        processList.add(0);
        processList.add(0);
        unionBase.setCurProcess(processList);
        unionBase.setInsertOption();
        return unionBase;
    }

    /**
     * 捐献道具
     */
    public static void donateItem(int activityId, String unionId, int type, int addValue) {
        StrongholdUnionBase unionBase = getUnionBase(activityId, unionId);
        synchronized (unionBase) {
            unionBase.addProcess(type, addValue);
            int nextLv = CrossStrongholdActivityMgr.getCurBaseLv(activityId,unionBase.getLv(), unionBase.getCurProcess());
            unionBase.setLv(nextLv);
        }
    }


    /**
     * 找出有资格参加淘汰赛的联盟
     *
     * @param activityId
     * @return
     */
//    private static Set<String> findQualifyList(int activityId) {
//        Set<String> qualifyList = getQualifyUnionList(activityId, false);
//        Map<Integer, StrongholdUploadMark> markMap = uploadMarkMap.get(activityId);
//        if (markMap == null) {
//            markMap = new ConcurrentHashMap<>();
//            uploadMarkMap.put(activityId, markMap);
//        }
//        int round = CrossStrongholdActivityMgr.getCurEmilinateRound(activityId);
//        StrongholdUploadMark mark = markMap.get(round);
//        boolean needSync = false;
//        if (mark == null) {
//            mark = new StrongholdUploadMark();
//            mark.setActivityId(activityId);
//            mark.setRound(round);
//            mark.setInsertOption();
//            needSync = true;
//            markMap.put(round, mark);
//        }
//        for (String unionId : qualifyList) {
//            mark.addQualifyUnion(unionId);
//        }
//        if (needSync) {
//            //重新通知玩家是否有资格
//          /*  for (GamePlayer player : GamePlayerMgr.getAllOnlinePlayer()) {
//                player.getModule(StrongholdModule.class).syncUserData();
//            }*/
//        }
//        return qualifyList;
//    }
    public static Set<String> getQualifyUnionList(int activityId, int groupId, boolean allServer) {
        Set<String> qualifyList = new HashSet<>();
        if (CrossStrongholdActivityMgr.isLookWildRank(activityId)) {
            //野外据点前几名
            int rankNum = CrossStrongholdActivityMgr.getQualifyNum(activityId);
            UnionActivityRankProto.UnionActivityRankListMsg rankList = getUnionRankListMsg(activityId, groupId, eGamePlayerEventType.StrongholdWildUnionScoreRank.getValue());//;CrossDataMgr.getCrossActivityUnionConditionTypeRankList(activityId, eGamePlayerEventType.StrongholdWildUnionScoreRank.getValue());
            if (rankList != null) {
                qualifyList.addAll(findServerQualifyUnion(rankNum, rankList, allServer));
            }
        } else {
            // 淘汰赛前几名
            int rankNum = CrossStrongholdActivityMgr.getQualifyNum(activityId);
            UnionActivityRankProto.UnionActivityRankListMsg rankList = getUnionRankListMsg(activityId, groupId, eGamePlayerEventType.StrongholdEliminateUnionRank.getValue());// CrossDataMgr.getCrossActivityUnionConditionTypeRankList(activityId, eGamePlayerEventType.StrongholdEliminateUnionRank.getValue());
            if (rankList != null) {
                qualifyList.addAll(findServerQualifyUnion(rankNum, rankList, allServer));
            }
        }
        return qualifyList;
    }

    private static UnionActivityRankProto.UnionActivityRankListMsg getUnionRankListMsg(int activityId, int groupId, int type) {
        CrossActivityUnionRankModel rankModel = CrossStrongholdRankMgr.getCrossActivityUnionRankListModel(activityId, groupId, type, true);
        return rankModel.getRankListMsg().build();
    }

    /**
     * 捐献银两
     */
    public static void donateSilver(int activityId, String unionId, long userId, BigInteger num, UserBaseInfo userBaseInfo, UnionBaseInfo unionBaseInfo) {
        synchronized (silverDonateMap) {
            Map<Long, StrongholdSilverDonate> donateMap = getUnionSilverDonateMap(activityId, unionId);
            StrongholdSilverDonate silverDonate = donateMap.get(userId);
            if (silverDonate == null) {
                silverDonate = new StrongholdSilverDonate();
                silverDonate.setUserId(userId);
                silverDonate.setNum(BigInteger.ZERO);
                silverDonate.setUnionUid(unionId);
                silverDonate.setActivityId(activityId);
                silverDonate.setInsertOption();
                donateMap.put(userId, silverDonate);
            }
            silverDonate.setUserBaseInfo(userBaseInfo);
            silverDonate.setNum(silverDonate.getNum().add(num));
        }
        Map<Long, StrongholdSilverDonate> donateMap = silverDonateMap.get(activityId).get(unionId);
        BigInteger total = BigInteger.ZERO;
        for (StrongholdSilverDonate donate : donateMap.values()) {
            total = total.add(donate.getNum());
        }
        //同步到跨服进行排名
        CrossActivityUnionRank unionRank = new CrossActivityUnionRank();
        unionRank.setActivityId(activityId);
        unionRank.setUnionUid(unionId);
        unionRank.setValue(total);
        unionRank.setLastUpdateTime(System.currentTimeMillis());
        unionRank.setUnionBaseInfo(unionBaseInfo);
      //  CrossDataMgr.strongholdUnionRankChange(activityId, eGamePlayerEventType.StrongholdDonateSilverRank.getValue(), unionRank);
        CrossStrongholdRankMgr.changeStrongholdUnionRank(activityId, eGamePlayerEventType.StrongholdDonateSilverRank.getValue(), unionRank, false);
    }

    /**
     * 获取联盟银两捐献内容
     *
     * @param activityId
     * @param unionId
     * @return
     */
    private static Map<Long, StrongholdSilverDonate> getUnionSilverDonateMap(int activityId, String unionId) {
        synchronized (silverDonateMap) {
            Map<String, Map<Long, StrongholdSilverDonate>> unionMap = silverDonateMap.get(activityId);
            if (unionMap == null) {
                unionMap = new ConcurrentHashMap<>(4);
                silverDonateMap.put(activityId, unionMap);
            }
            Map<Long, StrongholdSilverDonate> donateMap = unionMap.get(unionId);
            if (donateMap == null) {
                donateMap = new ConcurrentHashMap<>(4);
                unionMap.put(unionId, donateMap);
            }
            return donateMap;
        }
    }

    /**
     * 获取联盟捐献进度
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    public static List<Integer> getDonateItemProcess(int activityId, String unionUid) {
        StrongholdUnionBase unionBase = getUnionBase(activityId, unionUid);
        return unionBase.getCurProcess();
    }

    /**
     * 获取道具捐献详情
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    public static List<StrongholdSilverDonate> getSilverDonateDetail(int activityId, String unionUid) {
        Map<Long, StrongholdSilverDonate> donateMap = getUnionSilverDonateMap(activityId, unionUid);
        return new ArrayList<>(donateMap.values());
    }



    /**
     * 获取淘汰赛血量加成
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    public static int getHpAdd(int activityId, String unionUid) {
        StrongholdUnionBase unionBase = getUnionBase(activityId, unionUid);
        int lv = unionBase.getLv();
        //千分比
        int unionBaseAdd = CrossStrongholdActivityMgr.getUnionBaseAdd(activityId, lv);
        int hpAddByRank = getHpAddBySilverRank(activityId, unionUid);
        return unionBaseAdd + hpAddByRank;
    }

    /**
     * 获取银两捐献排行加成
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    private static int getHpAddBySilverRank(int activityId, String unionUid) {
        int rank = getSilverRank(activityId, unionUid);
        //千分比
        return CrossStrongholdActivityMgr.getHpAddByRank(activityId, rank);
    }

    /**
     * 获取银两捐献排行
     * -1:未上榜
     * 0：已淘汰
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    public static int getSilverRank(int activityId, String unionUid) {
        int groupId = Cross2UnionActivityGroupMgr.getGroupId(activityId, unionUid);
        Collection<String> allQualifyUnion = getQualifyUnionList(activityId, groupId, true);
        if (!allQualifyUnion.contains(unionUid)) {
            return 0;
        }

        int myRank = -1;
        LinkedList<CrossActivityUnionRank> rankList = CrossStrongholdRankMgr.getCrossActivityUnionRankListModel(activityId, groupId, eGamePlayerEventType.StrongholdDonateSilverRank.getValue(), true).getRankList();
        if (rankList == null) {
            return myRank;
        }
        int rank = 0;
        for (CrossActivityUnionRank unionRank : rankList) {
            String uid = unionRank.getUnionUid();
            if (allQualifyUnion.contains(uid)) {
                rank++;
                if (Objects.equals(uid,unionUid)) {
                    myRank = rank;
                    break;
                }
            }
        }

        return myRank;
    }


    /**
     * 找出本服有资格的联盟
     *
     * @param rankNum
     * @param rankList
     * @param allServer
     * @return
     */
    private static List<String> findServerQualifyUnion(int rankNum, UnionActivityRankProto.UnionActivityRankListMsg rankList, boolean allServer) {
        int rank = 0;
        List<String> unionUidList = new ArrayList<>();
        for (UnionActivityRankProto.UnionActivityRankTempMsg msg : rankList.getRankListList()) {
            rank++;
            String unionUid = msg.getUnionUid();
            if (allServer) {
                unionUidList.add(unionUid);
            }
            if (rank >= rankNum) {
                break;
            }
        }
        return unionUidList;
    }


    /**
     * 获取淘汰赛联盟防守门客信息
     *
     * @param activityId
     * @param unionId
     * @return
     */
//    public static List<StrongholdEliminateDefendPatrons> getEliminateDefendList(int activityId, String unionId) {
//        List<StrongholdEliminateDefendPatrons> patronsList = new ArrayList<>();
//        Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>> unionMap = defendPatronsMap.get(activityId);
//        if (unionMap == null) {
//            return patronsList;
//        }
//        Map<Long, List<StrongholdEliminateDefendPatrons>> patronsMap = unionMap.get(unionId);
//        if (patronsMap == null) {
//            return patronsList;
//        }
//        for (List<StrongholdEliminateDefendPatrons> defendPatronsList : patronsMap.values()) {
//            for (StrongholdEliminateDefendPatrons patrons : defendPatronsList) {
//                if (patrons.getPatrons() != null) {
//                    patronsList.add(patrons);
//                }
//            }
//        }
//        return patronsList;
//    }

    /**
     * 判断联盟是否有资格
     *
     * @param activityId
     * @param unionUid
     * @return
     */
//    public static boolean hasQualification(int activityId, String unionUid) {
//        Map<Integer, StrongholdUploadMark> markMap = StrongholdWarMgr.uploadMarkMap.get(activityId);
//        if (markMap == null) {
//            return false;
//        }
//        int round = CrossStrongholdActivityMgr.getCurEmilinateRound(activityId);
//        StrongholdUploadMark mark = markMap.get(round);
//        if (mark == null) {
//            return false;
//        }
//        return mark.getQualifyUnionList().contains(unionUid);
//    }

    /**
     * 获取玩家淘汰赛防守门客
     *
     * @param activityId
     * @param unionUid
     * @param userId
     * @return
     */
//    public static List<Integer> getEliminateDefendPatrons(int activityId, String unionUid, long userId) {
//        Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>> unionMap = defendPatronsMap.get(activityId);
//        List<Integer> list = new ArrayList<>();
//        if (unionMap == null) {
//            return list;
//        }
//        Map<Long, List<StrongholdEliminateDefendPatrons>> patronsMap = unionMap.get(unionUid);
//        if (patronsMap == null) {
//            return list;
//        }
//        List<StrongholdEliminateDefendPatrons> patronsList = patronsMap.get(userId);
//        if (patronsList == null) {
//            return list;
//        }
//        for (StrongholdEliminateDefendPatrons patrons : patronsList) {
//            if (patrons.getPatrons() != null) {
//                list.add(patrons.getPatrons().getPatronsId());
//            }
//        }
//        return list;
//    }

    /**
     * 西域通商
     *
     * @param activityId
     * @param userId
     * @param unionUid
     */
    public static void addTrade(int activityId, long userId, String unionUid) {
        Map<Long, StrongholdTradeData> dataMap = tradeMap.get(activityId);
        if (dataMap == null) {
            dataMap = new ConcurrentHashMap<>();
            tradeMap.put(activityId, dataMap);
        }
        StrongholdTradeData data = dataMap.get(userId);
        if (data != null) {
            return;
        }
        data = new StrongholdTradeData();
        data.setActivityId(activityId);
        data.setUserId(userId);
        data.setUnionId(unionUid);
        data.setTradeTime(System.currentTimeMillis() / 1000);
        data.setInsertOption();
        dataMap.put(data.getUserId(), data);
    }

    /**
     * 联盟西域通商成员
     *
     * @param activityId
     * @param userIdList
     * @return
     */
    public static Set<Long> getUnTradeUserList(int activityId, List<Long> userIdList) {
        Set<Long> userIdSet = new HashSet<>();
        Map<Long, StrongholdTradeData> dataMap = tradeMap.get(activityId);
        if (dataMap == null) {
            userIdSet.addAll(userIdList);
            return userIdSet;
        }
        for (Long userId : userIdList) {
            if (!dataMap.containsKey(userId)) {
                userIdSet.add(userId);
            }
        }
        return userIdSet;
    }

    /**
     * 玩家西域通商地址
     *
     * @param activityId
     * @param userId
     * @return
     */
//    public static int getMyTradeAddress(int activityId, long userId) {
//        Map<Long, StrongholdTradeData> dataMap = tradeMap.get(activityId);
//        if (dataMap == null) {
//            return 0;
//        }
//        for (StrongholdTradeData data : dataMap.values()) {
//            if (data.getUserId() == userId) {
//                return data.getAddressId();
//            }
//        }
//        return 0;
//    }

    /**
     * 联盟道具捐献等级
     *
     * @param activityId
     * @param unionUid
     * @return
     */
    public static int getUnionBaseLv(int activityId, String unionUid) {
        StrongholdUnionBase unionBase = getUnionBase(activityId, unionUid);
        return unionBase.getLv();
    }


    public static void userDonate(int activityId, String unionId, long userId, int type, int addValue) {
        StrongholdItemDonate donate = getUserItemDonateData(activityId, unionId, userId, type);
        donate.setValue(donate.getValue() + addValue);
    }

    private static StrongholdItemDonate getUserItemDonateData(int activityId, String unionId, long userId, int type) {
        synchronized (itemDonateMap) {
            Map<String, Map<Long, Map<Integer, StrongholdItemDonate>>> unionMap = itemDonateMap.get(activityId);
            if (unionMap == null) {
                unionMap = new ConcurrentHashMap<>();
                itemDonateMap.put(activityId, unionMap);
            }
            Map<Long, Map<Integer, StrongholdItemDonate>> userMap = unionMap.get(unionId);
            if (userMap == null) {
                userMap = new ConcurrentHashMap<>();
                unionMap.put(unionId, userMap);
            }
            Map<Integer, StrongholdItemDonate> donateMap = userMap.get(userId);
            if (donateMap == null) {
                donateMap = new ConcurrentHashMap<>();
                userMap.put(userId, donateMap);
            }
            StrongholdItemDonate donate = donateMap.get(type);
            if (donate == null) {
                donate = new StrongholdItemDonate();
                donate.setActivityId(activityId);
                donate.setUnionUid(unionId);
                donate.setUserId(userId);
                donate.setType(type);
                donate.setValue(0);
                donate.setInsertOption();
                donateMap.put(type, donate);
            }
            return donate;
        }
    }

    public static Map<Long, Integer> getMemberItemDonateList(int activityId, String unionUid, int type) {
        Map<Long, Integer> dataMap = new HashMap<>();
        Map<String, Map<Long, Map<Integer, StrongholdItemDonate>>> unionMap = itemDonateMap.get(activityId);
        if (unionMap == null) {
            return dataMap;
        }
        Map<Long, Map<Integer, StrongholdItemDonate>> userMap = unionMap.get(unionUid);
        if (userMap == null) {
            return dataMap;
        }
        for (Map<Integer, StrongholdItemDonate> donateMap : new ArrayList<>(userMap.values())) {
            for (StrongholdItemDonate donate : new ArrayList<>(donateMap.values())) {
                long userId = donate.getUserId();
                if (!dataMap.containsKey(userId)) {
                    dataMap.put(userId, 0);
                }
                dataMap.put(userId, dataMap.get(userId) + donate.getValue());
            }
        }

        return dataMap;
    }


    @Override
    public boolean reloadData() throws Exception {
        if (silverDonateMap == null) {
            silverDonateMap = new ConcurrentHashMap<>();
        }

        if (itemDonateMap == null) {
            itemDonateMap = new ConcurrentHashMap<>();
        }

        if (defendPatronsMap == null) {
            defendPatronsMap = new ConcurrentHashMap<>();
        }

        if (activityUnionBaseMap == null) {
            activityUnionBaseMap = new ConcurrentHashMap<>(2);
        }
        if (tradeMap == null) {
            tradeMap = new ConcurrentHashMap<>();
        }

        Set<Integer> activityIdSet = CrossStrongholdActivityMgr.getOpenActivityInfoMap().keySet();
        for (Integer activityId : activityIdSet) {
            Map<String, Map<Long, StrongholdSilverDonate>> donateMap = new CrossStrongholdSilverDonateDaoImpl().getStrongholdSilverDonate(activityId);
            silverDonateMap.put(activityId, donateMap);
            Map<String, StrongholdUnionBase> unionBaseMap = new CrossStrongholdUnionBaseDaoImpl().getStrongholdUnionBase(activityId);
            activityUnionBaseMap.put(activityId, unionBaseMap);

           /* Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>> unionPatronsMap = UserStrongholdBusiness.getEliminatePatrons(activityId);
            defendPatronsMap.put(activityId, unionPatronsMap);*/
           /* Map<Integer, StrongholdUploadMark> markMap = UserStrongholdBusiness.getUploadMarkMap(activityId);
            uploadMarkMap.put(activityId, markMap);
            Map<Long, StrongholdTradeData> dataMap = UserStrongholdBusiness.getStrongholdTradeMap(activityId);
            tradeMap.put(activityId, dataMap);*/
            itemDonateMap.put(activityId, new CrossStrongholdItemDonateDaoImpl().getStrongholdItemDonate(activityId));
        }
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    private static boolean noticeTradeRed;

    @Override
    public boolean save() {
        for (Map<String, Map<Long, StrongholdSilverDonate>> activityMap : silverDonateMap.values()) {
            for (Map<Long, StrongholdSilverDonate> donateMap : new ArrayList<>(activityMap.values())) {
                for (StrongholdSilverDonate donate : new ArrayList<>(donateMap.values())) {
                    if (donate.isInsertOption()) {
                        new CrossStrongholdSilverDonateDaoImpl().add(donate);
                    } else if (donate.isUpdateOption()) {
                        new CrossStrongholdSilverDonateDaoImpl().update(donate);
                    }
                }
            }
        }

        for (Map<String, StrongholdUnionBase> unionBaseMap : activityUnionBaseMap.values()) {
            for (StrongholdUnionBase unionBase : new ArrayList<>(unionBaseMap.values())) {
                if (unionBase.isInsertOption()) {
                    new CrossStrongholdUnionBaseDaoImpl().add(unionBase);
                } else if (unionBase.isUpdateOption()) {
                    new CrossStrongholdUnionBaseDaoImpl().update(unionBase);
                }
            }
        }


        for (Map<String, Map<Long, List<StrongholdEliminateDefendPatrons>>> unionMap : defendPatronsMap.values()) {
            for (Map<Long, List<StrongholdEliminateDefendPatrons>> patronsMap : new ArrayList<>(unionMap.values())) {
                for (List<StrongholdEliminateDefendPatrons> patronsList : new ArrayList<>(patronsMap.values())) {
                    for (StrongholdEliminateDefendPatrons patrons : patronsList) {
                        if (patrons.isInsertOption()) {
                            UserStrongholdBusiness.addEliminatePatrons(patrons);
                        } else if (patrons.isUpdateOption()) {
                            UserStrongholdBusiness.updateEliminatePatrons(patrons);
                        }
                    }
                }
            }
        }

       /* for (Map<Integer, StrongholdUploadMark> markMap : uploadMarkMap.values()) {
            for (StrongholdUploadMark mark : markMap.values()) {
                if (mark.isInsertOption()) {
                    UserStrongholdBusiness.addUploadMark(mark);
                } else if (mark.isUpdateOption()) {
                    UserStrongholdBusiness.updateUploadMark(mark);
                }
            }
        }*/

        /*for (Map<Long, StrongholdTradeData> dataMap : tradeMap.values()) {
            for (StrongholdTradeData data : new ArrayList<>(dataMap.values())) {
                if (data.isInsertOption()) {
                    UserStrongholdBusiness.addStrongholdTrade(data);
                } else if (data.isUpdateOption()) {
                    UserStrongholdBusiness.updateStrongholdTrade(data);
                }
            }
        }*/

        for (Map<String, Map<Long, Map<Integer, StrongholdItemDonate>>> mapMap : itemDonateMap.values()) {
            for (Map<Long, Map<Integer, StrongholdItemDonate>> map : new ArrayList<>(mapMap.values())) {
                for (Map<Integer, StrongholdItemDonate> donateMap : new ArrayList<>(map.values())) {
                    for (StrongholdItemDonate donate : new ArrayList<>(donateMap.values())) {
                        if (donate.isInsertOption()) {
                            new CrossStrongholdItemDonateDaoImpl().add(donate);
                        } else if (donate.isUpdateOption()) {
                            new CrossStrongholdItemDonateDaoImpl().update(donate);
                        }
                    }
                }
            }
        }

        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }
}
